package com.springboot.service.system;

import com.springboot.dao.SystemUserRoleDao;
import com.springboot.entity.SystemUserRoleEntity;
import com.springboot.returndata.dto.AddUpdateUserRoleDto;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import jakarta.annotation.Resource;

/**
 * <p>
 * 用户角色表 服务实现类
 * </p>
 *
 * @author zyj
 * @since 2023-02-24
 */
@Service
@Slf4j
public class SystemUserRoleService extends ServiceImpl<SystemUserRoleDao, SystemUserRoleEntity> {

        @Resource
        private SystemUserRoleDao systemUserRoleEntityDao;

        /**
         *
         * @param addUpdateResourceDto
         * @throws Exception
         */
        @Transactional(rollbackFor = Exception.class)
        public void addUpdateUserRole(AddUpdateUserRoleDto addUpdateResourceDto) throws Exception{
                //根据用户id删除
                systemUserRoleEntityDao.deleteByUserId(addUpdateResourceDto.getUserId());

                //新增角色权限
                systemUserRoleEntityDao.addUpdateUserRole(addUpdateResourceDto);
        }
}

